-
Notifications
You must be signed in to change notification settings - Fork 779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix error handling #481
base: master
Are you sure you want to change the base?
fix error handling #481
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! A couple of fixed still needed, though.
@@ -288,7 +288,11 @@ NVGcontext* nvgCreateInternal(NVGparams* params) | |||
FONSparams fontParams; | |||
NVGcontext* ctx = (NVGcontext*)malloc(sizeof(NVGcontext)); | |||
int i; | |||
if (ctx == NULL) goto error; | |||
if (ctx == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be (ctx->params is not set yet either):
if (ctx == NULL) {
// Call renderer delete explicitly. Context is not initialized yet, so we cannot call nvgDeleteInternal() which usually calls the function.
if (params->renderDelete != NULL)
params->renderDelete(params->userPtr);
return NULL;
}
src/nanovg_gl.h
Outdated
@@ -1590,7 +1590,6 @@ NVGcontext* nvgCreateGLES3(int flags) | |||
|
|||
error: | |||
// 'gl' is freed by nvgDeleteInternal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove comment
Updated) |
Is changes good? Anything needed from my side? |
ctx can't be != NULL on error path, nvgDeleteInternal can return immediately (if (ctx == NULL) return;) without userPtr cleanup => "gl" can leak.